namespace EntityFrameworkStudy.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddLevelThree : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Level1",
                c => new
                    {
                        Level1Id = c.Int(nullable: false, identity: true),
                    })
                .PrimaryKey(t => t.Level1Id);
            
            CreateTable(
                "dbo.Level2",
                c => new
                    {
                        Level2Id = c.Int(nullable: false, identity: true),
                        Level1Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Level2Id, t.Level1Id })
                .ForeignKey("dbo.Level1", t => t.Level1Id, cascadeDelete: true)
                .Index(t => t.Level1Id);
            
            CreateTable(
                "dbo.Level3",
                c => new
                    {
                        Level3Id = c.Int(nullable: false, identity: true),
                        Level2Id = c.Int(nullable: false),
                        Level1Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.Level3Id, t.Level2Id, t.Level1Id })
                .ForeignKey("dbo.Level2", t => new { t.Level2Id, t.Level1Id }, cascadeDelete: true)
                .Index(t => new { t.Level2Id, t.Level1Id });
            
        }
        
        public override void Down()
        {
            DropIndex("dbo.Level3", new[] { "Level2Id", "Level1Id" });
            DropIndex("dbo.Level2", new[] { "Level1Id" });
            DropForeignKey("dbo.Level3", new[] { "Level2Id", "Level1Id" }, "dbo.Level2");
            DropForeignKey("dbo.Level2", "Level1Id", "dbo.Level1");
            DropTable("dbo.Level3");
            DropTable("dbo.Level2");
            DropTable("dbo.Level1");
        }
    }
}
